#!/usr/bin/env python
"""
Nagios plugin that monitors MyProxy service 
"""

__author__="Placi Flury grid@switch.ch"
__copyright__ = "Copyright 2010, SMSCG an AAA/SWITCH project"
__date__="24.11.2008"
__version__="0.1.0"

import sys
from nagios_plugin import NagiosPluginBasic,LocalService

MYPROXYPID_LOCATION="/opt/globus/var"

class MyProxyServer(NagiosPluginBasic):
    """
    Checks whether MyProxy service is running. It's a local check
    without any connectivity testing.
    """
    def __init__(self):
        parser = NagiosPluginBasic.getOptions(self)
        parser.remove_option("-c")   # removing thresholds
        parser.remove_option("-w")
        parser.remove_option("-H")   # remove hostname option
        parser.parse_args()


    def main(self):

        service = LocalService("myproxy", MYPROXYPID_LOCATION)
        msg, return_code = service.getstate()

        print msg
        sys.exit(return_code)


if __name__ =="__main__":
    g = MyProxyServer()
    g.main()
